{{template "header"}}
<title>分类——我的11go_http</title>
</head>
<body>
<nav class="navbar navbar-default navbar-fixed-top">
    {{template "nav" .}}
    <div class="container">

        <h1>分类列表</h1>

        <form  method="get" action="/category">
            <div class="form-group">
                <label >分类名称</label>
                <input  id="catename" class="form-control" placeholder="请输入类别名称" name="catename">
            </div>
            <input type="hidden" value="add" name="op">
            <input type="hidden" name="rand" value="{{.}}">

            <button type="submit" class="btn btn-default" onclick="return addCate();">添加</button>
            <button class="btn btn-default" onclick="return backHome();">返回</button>
        </form>

        <table class="table table-striped">
            <thead>
                <tr>
                    <th>#</th>
                    <th>名称</th>
                    <th>文章数</th>
                    <th>操作</th>
                </tr>
            </thead>
                {{range .Categories}}
                    <tbody>
                            <th>{{.Id}}</th>
                            <th>{{.Title}}</th>
                            <th>{{.TopicCount}}</th>
                            <th><a href="/category?op=del&id={{.Id}}">删除</a></th>
                    </tbody>
            {{end}}
        </table>
    </div>


    <script type ="text/javascript">
    function addCate() {
        var catename = document.getElementById("catename");
        if (catename.value.length ==0){
        alert("请输入分类名称")
            var rand =Math.random()

            var randname = document.getElementsByName("catename");
            randname.values=Math.random()

        return false
    }

    return true

    }

    function backHome() {
    window.location.href="/"
    return false
    }
    </script>
    <script type="text/javascript" src="http://code.jquery.com/jquery-3.2.1.min.js"></script>
    <script type="text/javascript" src="/static/plugin/bootstrap/dist/js/bootstrap.js"></script>

</nav></body>
</html>
